﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;

namespace WeiXin
{
    public partial class FormSet : Form
    {
        DataTable dt = new DataTable();
        public static readonly string fileName = "file.xml";
        public FormSet()
        {
            InitializeComponent();
            dt.TableName = "TableName";
            dt.Columns.Add("关键字", Type.GetType("System.String"));
            dt.Columns.Add("回复内容", Type.GetType("System.String"));
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(textBox1.Text) && !string.IsNullOrEmpty(textBox2.Text))
            {
                DataRow dr = dt.NewRow();
                dr["关键字"] = textBox1.Text;
                dr["回复内容"] = textBox2.Text;
                dt.Rows.Add(dr);
                DataBind();
                saveData();
            }
        }

        private void saveData()
        {
            this.dt.WriteXml(fileName);
        }

        private void FormSet_Load(object sender, EventArgs e)
        {
            if (File.Exists(fileName))
            {

                this.dt.ReadXml(fileName);
                DataBind();
            }
        }

        private void DataBind()
        {
            dataGridView1.DataSource = dt;
        }



        private void button2_Click(object sender, EventArgs e)
        {
            //listBox1.Items.Remove(listBox1.SelectedItem);

            //File.WriteAllText(@"file\data.txt", "");

            //foreach (var item in listBox1.Items)
            //{
            //    saveData(item.ToString());
            //}
        }
    }
}
